import 'package:earclean/app/config/colors.dart';
import 'package:earclean/app/routes/app_pages.dart';
import 'package:earclean/app/util/common_utils.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/src/size_extension.dart';
import 'package:get/get.dart';
import 'package:shanyan/shanYanResult.dart';
import 'package:shanyan/shanyan.dart';

class ServiceTermsWidget extends StatefulWidget {
  const ServiceTermsWidget({Key? key}) : super(key: key);

  @override
  State<ServiceTermsWidget> createState() => _ServiceTermsWidgetState();
}

class _ServiceTermsWidgetState extends State<ServiceTermsWidget> {
  @override
  void initState() {
    super.initState();
  }

  initSy() async {
    // 初始化一键登录测试 com.253.QuanJu11 aj9SzHra
    // 初始化一键登 com.bomeng.nightmam 9vcKFnUr
    // String appId = "aj9SzHra";
    String appId = "9vcKFnUr";
    //
    ShanYanResult value = await OneKeyLoginManager().init(appId: appId);
    if (value.code == 1000) {
      OneKeyLoginManager().getPhoneInfo().then((value) {
        if (value.code == 1000) {
          box.write('oneKeyInit', true);
        } else {
          box.write('oneKeyInit', false);
        }
      });
    } else {
      box.write('oneKeyInit', false);
    }
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child: SingleChildScrollView(
        child: Container(
          color: ColorConfig.white,
          child: Column(
            children: [
              Container(
                padding: EdgeInsets.only(top: 26.h, bottom: 27.h),
                child: Text(
                  '服务协议与隐私政策',
                  style: TextStyle(
                      color: ColorConfig.text_label,
                      fontSize: 18.sp,
                      fontWeight: FontWeight.bold),
                ),
              ),
              Container(
                padding: EdgeInsets.symmetric(horizontal: 15.w),
                child: RichText(
                    text: TextSpan(
                  children: [
                    TextSpan(
                      text:
                          '请你务必审慎阅读、充分理解“隐私政策”各条款，包括但不限于:为了更好的向你提供服务，我们需要收集你的设备标识、操作日志等信息用于分析、优化应用性能你可阅读',
                    ),
                    TextSpan(
                        text: '《用户协议》',
                        recognizer: TapGestureRecognizer()
                          ..onTap = () {
                            Get.toNamed(Routes.WEB, arguments: {
                              "title": '用户协议',
                              "url":
                                  'https://iamz.jiliol.net/LegalDocuments/UserAgreement.html',
                            });
                          },
                        style: TextStyle(
                            fontSize: 13.sp, color: ColorConfig.app_main)),
                    TextSpan(
                        text: '和',
                        style: TextStyle(
                            fontSize: 13.0.sp,
                            color: ColorConfig.subtitle_text)),
                    TextSpan(
                        text: '《隐私政策》',
                        recognizer: TapGestureRecognizer()
                          ..onTap = () {
                            Get.toNamed(Routes.WEB, arguments: {
                              "title": '隐私政策',
                              "url":
                                  'https://iamz.jiliol.net/LegalDocuments/PrivacyPolicy.html',
                            });
                          },
                        style: TextStyle(
                            fontSize: 13.sp, color: ColorConfig.app_main)),
                    TextSpan(
                      text: '了解详细信息。如果你同意，请点击下面按钮开始接受我们的服务。',
                    ),
                  ],
                  style: TextStyle(
                    color: ColorConfig.subtitle_text,
                    fontSize: 13.sp,
                  ),
                )),
              ),

              Container(
                padding: EdgeInsets.only(top: 30.h, bottom: 36.h),
                margin: EdgeInsets.symmetric(horizontal: 15.w),
                child: Row(
                  children: [
                    Expanded(
                      child: Container(
                        height: 45,
                        child: ElevatedButton(
                          style: ElevatedButton.styleFrom(
                              primary: ColorConfig.white,
                              shape: RoundedRectangleBorder(
                                side: BorderSide(
                                    color: ColorConfig.app_main, width: 1),
                                borderRadius: BorderRadius.circular(10),
                              )),
                          onPressed: () {
                            Get.back(result: 0);
                          },
                          child: Text('暂不同意',
                              style: TextStyle(
                                  fontSize: 15.sp,
                                  color: ColorConfig.subtitle_text,
                                  fontWeight: FontWeight.w400)),
                        ),
                      ),
                    ),
                    SizedBox(
                      width: 21.w,
                    ),
                    Expanded(
                      child: Container(
                        height: 45,
                        child: ElevatedButton(
                          style: ElevatedButton.styleFrom(
                              primary: ColorConfig.app_main,
                              shape: RoundedRectangleBorder(
                                borderRadius: BorderRadius.circular(10),
                              )),
                          onPressed: () {
                            Get.back(result: 1);
                          },
                          child: Text('同意并继续',
                              style: TextStyle(
                                  fontSize: 15.sp,
                                  color: ColorConfig.white,
                                  fontWeight: FontWeight.w400)),
                        ),
                      ),
                    ),
                  ],
                ),
              )
              // TextButton(
              //     onPressed: () {
              //       Get.back(result: 0);
              //     },
              //     child: Text('不同意并退出',
              //         style: TextStyle(
              //             fontSize: 14.sp,
              //             color: ColorConfig.white,
              //             fontFamily: 'mononoki')))
            ],
          ),
        ),
      ),
    );
  }
}
